//
//  LGFollowTitleGrayHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//  标题区头

#import "LGFollowTitleGrayHeader.h"

@interface LGFollowTitleGrayHeader()

/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *subTitleLabel;

@end

@implementation LGFollowTitleGrayHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        [self addSubview:self.titleLabel];
        [self addSubview:self.subTitleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-viewPix(2));
            make.centerX.equalTo(self).offset(0);
        }];
        [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_right);
            make.bottom.equalTo(self.titleLabel);
        }];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
}

-(void)setSubTitle:(NSString *)subTitle{
    _subTitle = subTitle;
    self.subTitleLabel.text = subTitle;
    CGFloat width = [subTitle textWidthWithFont:LGFont(15) maxHeight:MAXFLOAT];
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self).offset(-width/2.0);
    }];
}


-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _titleLabel;
}

-(UILabel *)subTitleLabel{
    if(!_subTitleLabel){
        _subTitleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _subTitleLabel;
}

@end
